package com.blue.blog.api.controller;

import com.blue.blog.api.pojo.Category;
import com.blue.blog.api.pojo.Result;
import com.blue.blog.api.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CategoryController {
    @Autowired
    private CategoryService service;

    @GetMapping("/categorys")
    public Result findAllCategory() {
        List<Category> categories = service.findAllCategory();

        return Result.ok("查询成功", categories);
    }

    @PostMapping("/category")
    public Result saveCategory(@RequestBody Category category) {
        Integer result = service.saveCategory(category);

        return Result.ok("添加成功!", result);
    }

    @PutMapping("/category")
    public Result updateCategory(@RequestBody Category category) {
        Integer result = service.updateCategory(category);

        return Result.ok("更新成功!", result);
    }

    @DeleteMapping("/category")
    public Result deleteCategoryById(@RequestParam Long id) {
        Integer result = service.deleteCategoryById(id);

        return Result.ok("删除成功!", result);
    }
}
